<?php

declare(strict_types=1);

namespace App\User\Model;

use Mine\MineModel;

/**
* @property int $id ID
* @property int $room_no 用户vip_id,随机，不可重复
* @property int $pid 父节点
* @property string $nickname 昵称
* @property string $avatar 头像
* @property string $mobile 手机号
* @property string $email 邮箱
* @property int $gender 性别0:未知,1男,2:女
* @property string $trade_url 交易联接
* @property int $is_flag 标识符,1-散户,2-内部用户
* @property int $is_real_name 是否已实名1实名，2 未实名
* @property string $login_last_ip 最后登陆ip
* @property string $login_last_time 最后登陆时间
* @property string $invite_code 邀请码
* @property int $source_type 来源类型
1:自已注册,2:通过邀请码注册，3.通过邀请链接注册
4:后台新增用户
* @property int $status 用户状态 1正常 2冻结 3:注销
* @property string $remark 备注或是签名(测试账号可能会做个备注)
* @property int $created_by 创建者
* @property int $create_time 创建时间
* @property int $update_time 更新时间
* @property int $delete_time 删除数据
*/
class UserInfo extends MineModel
{

    protected ?string $dateFormat = 'U';
    const CREATED_AT = 'create_time';
    const UPDATED_AT = 'update_time';
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'user_info';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['id', 'room_no', 'pid', 'nickname', 'avatar', 'mobile', 'email', 'gender', 'trade_url', 'is_flag', 'is_real_name', 'login_last_ip', 'login_last_time', 'invite_code', 'source_type', 'status', 'remark', 'created_by', 'create_time', 'update_time', 'delete_time'];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'room_no' => 'integer', 'pid' => 'integer', 'gender' => 'integer', 'is_flag' => 'integer', 'is_real_name' => 'integer', 'source_type' => 'integer', 'status' => 'integer', 'created_by' => 'integer', 'create_time' => 'integer', 'update_time' => 'integer', 'delete_time' => 'integer'];

    const REDIS_MAKE_ROOM_NO = 'user-serv:room:no:user';
    const REDIS_MAKE_INVITE_NO = 'user-serv::invite:user';

    public function account(){
        return $this->hasOne(UserAccount::class,'id','id');
    }

    public function getCreateTimeAttribute($value)
    {
        return empty($value) ? '' : date('Y-m-d H:i:s', (int)$value);
    }
}
